package cn.com.bluemoon.daps.standard.service.impl;

import cn.com.bluemoon.daps.common.constant.DapConstant;
import cn.com.bluemoon.daps.common.toolkit.BmAssetUtils;
import cn.com.bluemoon.daps.model.dto.ModelDto;
import cn.com.bluemoon.daps.standard.common.report.IReportCheck;
import cn.com.bluemoon.daps.standard.entity.DapAuditSystemResult;
import cn.com.bluemoon.daps.common.enums.AuditCheckType;
import org.springframework.stereotype.Component;

/**
 * 稽核结果
 *
 * @author Jarod Kong
 * @date 2020-09-25 22:43
 **/
@Component(DapConstant.AUDIT_SYSTEM_REPORT_MAIN)
public class MainReportCheckImpl implements IReportCheck {

    @Override
    public boolean generate(ModelDto modelDto) {
        String systemId = modelDto.getSystemId();
        String sysAuditCheckResultId = modelDto.getSysAuditCheckResultId();
        String sysAuditMainResultId = modelDto.getSysAuditMainResultId();
        BmAssetUtils.notNull(sysAuditCheckResultId, "稽核报告结果表id不可为空");
        BmAssetUtils.notNull(sysAuditMainResultId, "稽核报告结果表的提供给系统稽核关联的id不可为空");
        BmAssetUtils.notNull(systemId, "系统id不可为空");
        // 增加先清空原有系统的报告
        boolean insert = false;
        AuditCheckType checkType = modelDto.getCheckType();
        if (checkType != null) {
            DapAuditSystemResult systemResult = new DapAuditSystemResult();
            systemResult.setCheckDesc(checkType.getCheckDesc());
            // 默认为通过（出于系统下模型表都为空考虑）
            systemResult.setCheckResult(1);
            systemResult.setCheckType(checkType.getCheckType());
            systemResult.setCheckTypeCode(checkType.getCode());
            systemResult.setSystemId(systemId);
            systemResult.setId(sysAuditCheckResultId);
            systemResult.setAuditResultId(sysAuditMainResultId);
            insert = systemResult.insert();
        }
        return insert;
    }
}
